home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / science / sm32a.zip / LIBRARY / NSOLVE.LI2 < prev    next >
Text File  |  1993-10-16  |  597b  |  22 lines

  1. # nsolve.sm
  2. # nsolve(cos(x)=x,x,x0) searches for a numeric solution to the 
  3. # equation expr1=expr2, starting with x=x0, using Newston's method.
  4. # It only searches for one solution near x0. x0=1 by default.
  5. # nsolve(cos(x)=x, x)
  6. # e.g. nsolve(sin(x)=0,x,3) gives x=3.14, nsolve(sin(x)=0,x,6)
  7. # gives x=6.28.
  8. # See also: solve, dsolve.
  9.  
  10. nsolve(y_,x_,x0_) := block(numeric:=on,
  11.     eq:=left(y)-right(y),
  12.     dy:=d(eq ,x),
  13.     x:=x0,
  14.     jj:=1,
  15.     repeat(x:=x-eq/dy, jj:=jj+1, abs(eq)<1e-3 or jj>10),
  16.     numeric:=off,
  17.     nsolve:=x,
  18.     clear(x),
  19.     x=nsolve,
  20.     local(jj))
  21. nsolve(y_,x_) := nsolve(y,x,1)
  22.